<?php
header("access-control-allow-origin:*");

include_once("./utils/db.php");
include_once("./utils/functions.php");

//获取数据
$courseName = $_POST["coursename"];
$credit = $_POST["credit"];
$period = $_POST["period"];
$content = $_POST["content"];
$departmentid = $_POST["departmentid"];

//sql
$sql = "insert into xk_course(coursename,credit,period,departmentid,content) values(?,?,?,?,?)";
//使用prepare方法插入数据
$stmt = $conn->prepare($sql);
//bind-param 中s代表字符串，i代表整型
$stmt->bind_param("siiis", $courseName, $credit, $period, $departmentid, $content);
//执行的结果如果小于等于0表示数据插入失败，如果为1 表示插入成功
$result = $stmt->execute();
$info = [];
if ($result) {
  $info = ["code" => 200, "msg" => "数据插入成功"];
} else {
  $info = ["code" => 0, "msg" => "数据插入失败"];
}
$stmt->close();
//输出
echo json_encode($info, JSON_UNESCAPED_UNICODE);
